package main

import Cache "./cache-server"
//import Cache "./cache"
import "fmt"
import "time"

const (
  //time 1 2 3 4 5s
  A = iota * time.Second
  B
  C
  D
  E
)
func main() {
  cache := Cache.NewCache()

   cache.SetMaxMemory("300B")
   fmt.Println("\n")
  //
  cache.Set("data",map[string]interface{}{"data": "text", "a":1},  D)
  cache.Set("data2",map[string]interface{}{"data2":2000,"b": "b"}, E)
  // default expire time is 0, means never expire.
  cache.Set("data3",map[string]string{"str":"string..."})
  cache.Set("bool",false, A)
  cache.Set("bool",true, E)
  cache.Set("int",1, E)
  cache.Set("int",100, E*3)
  cache.Del("int")
  fmt.Println("\n")
  //
  datas := [...]string{"data","data2","data3","bool","int"}
  for _, key := range datas {
    cache.Get(key)
    // val,ok := cache.Get(key)
    // if ok {
    //   fmt.Println(key, ": ", val)
    // } else{
    //   fmt.Println(key, ": ", "Get failed.")
    // }
  }
  fmt.Println("\n")
  //
  cache.Exists("data2")
  cache.Del("data2")
  cache.Del("data2")
  cache.Exists("data2")
  fmt.Println("\n")
  //
  fmt.Println("sleep 3s")
  time.Sleep(time.Second*3)
  for _, str:= range datas {
    cache.Get(str)
    cache.Exists(str)
    cache.Keys()
  }
  fmt.Println("\n")


  time.Sleep(time.Second*10)
  for _, str:= range datas {
    cache.Get(str)
    cache.Set(str,"data")
  }
  cache.Flush()
}

